package com.max.eshop.services;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.max.eshop.storage.Storage;

public class OrderService {
	Storage s;

	public OrderService(Storage storage) {
		this.s = storage;
	}

	public void show() {
		s.showOrders();
	}

	public void add(String name, Integer count) {
		s.addOrder(name, count);
	}

	public void delete(int i) {
		s.deleteOrder(i - 1);
	}

	public void execute(int i) {
		s.executeOrder(i - 1);
	}

	public void showExecute(String ot, String before, String What) {
		Date dateOt = null;
		Date dateBefore = null;
		try {
			dateOt = new SimpleDateFormat("dd.MM.yyyy").parse(ot);
			dateBefore = new SimpleDateFormat("dd.MM.yyyy").parse(before);

		} catch (ParseException e) {
			e.printStackTrace();
		}
		if (What.equals("count")) {
			s.showCountExecuteOrder(dateOt, dateBefore);
		} else if (What.equals("list")) {
			s.showExecuteOrder(dateOt, dateBefore);
		} else if (What.equals("sum")) {
			s.showSumExecuteOrder(dateOt, dateBefore);
		} else {
			System.out.println("Unknown command");
		}
	}
 public Integer count(){
	 return s.countOrders();
 }
	public void sortedByStatus() {
		s.sortedOrdersByStatus();
	}

	public void sortedByPrice() {
		s.sortedOrdersByPrice();
	}

	public void sortedByDate() {
		s.sortedOrdersByDate();
	}

	public void sortedExecuteOrdersByPrice() {
		s.sortedExecuteOrdersByPrice();
	}

	public void sortedExecuteOrdersByDate() {
		s.sortedExecuteOrdersByDate();
	}
}
